package com.hxc.web.controller.interest;

import java.util.List;

import com.hxc.common.constant.HttpStatus;
import com.hxc.enums.DelTypes;
import com.hxc.enums.PutTypes;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hxc.common.annotation.Log;
import com.hxc.common.core.controller.BaseController;
import com.hxc.common.core.domain.AjaxResult;
import com.hxc.common.enums.BusinessType;
import com.hxc.interest.domain.TReactionInfo;
import com.hxc.interest.service.ITReactionInfoService;
import com.hxc.common.utils.poi.ExcelUtil;
import com.hxc.common.core.page.TableDataInfo;

/**
 * 反馈信息Controller
 * 
 * @author hxc
 * @date 2021-08-17
 */
@Api(tags = "事件反馈管理")
@RestController
@RequestMapping("/interest/reaction")
public class TReactionInfoController extends BaseController
{
    @Autowired
    private ITReactionInfoService tReactionInfoService;

    /**
     * 查询反馈信息列表
     */
    @PreAuthorize("@ss.hasPermi('interest:reaction:list')")
    @GetMapping("/list")
    public TableDataInfo list(TReactionInfo tReactionInfo)
    {
        startPage();
        //删除标识 0默认
        tReactionInfo.setDelFlag(DelTypes.NO.getCode());
        List<TReactionInfo> list = tReactionInfoService.selectTReactionInfoList(tReactionInfo);
        return getDataTable(list);
    }

    /**
     * 导出反馈信息列表
     */
    @PreAuthorize("@ss.hasPermi('interest:reaction:export')")
    @Log(title = "反馈信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TReactionInfo tReactionInfo)
    {
        List<TReactionInfo> list = tReactionInfoService.selectTReactionInfoList(tReactionInfo);
        ExcelUtil<TReactionInfo> util = new ExcelUtil<TReactionInfo>(TReactionInfo.class);
        return util.exportExcel(list, "反馈信息数据");
    }

    /**
     * 获取反馈信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('interest:reaction:query')")
    @GetMapping("/getInfo")
    public AjaxResult getInfo(TReactionInfo tReactionInfo)
    {
        //只查询自发事件信息
        tReactionInfo.setSendType(PutTypes.ZIFA.getCode());
        return AjaxResult.success(tReactionInfoService.selectTReactionInfo(tReactionInfo));
    }

    /**
     * 新增反馈信息
     */
    @ApiOperation(value = "添加反馈信息", notes = "添加")
    @PreAuthorize("@ss.hasPermi('interest:reaction:add')")
    @Log(title = "反馈信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TReactionInfo tReactionInfo)
    {
        if(tReactionInfo.getVillagerId() == null){
            AjaxResult.error(HttpStatus.BAD_REQUEST,"请求参数不合法");
        }
        return toAjax(tReactionInfoService.insertTReactionInfo(tReactionInfo));
    }

    /**
     * 修改反馈信息
     */
    @PreAuthorize("@ss.hasPermi('interest:reaction:edit')")
    @Log(title = "反馈信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TReactionInfo tReactionInfo)
    {
        return toAjax(tReactionInfoService.updateTReactionInfo(tReactionInfo));
    }

    /**
     * 删除反馈信息
     */
    @ApiOperation(value = "删除反馈信息", notes = "删除")
    @PreAuthorize("@ss.hasPermi('interest:reaction:remove')")
    @Log(title = "反馈信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        //批量删除(反馈与用户中间表)信息，主体数据不删除
        return toAjax(tReactionInfoService.deleteTReactionInfoByIds(ids));
    }

    /**
     * 功能描述: 根据id查询事件详情
     * @author yzj
     */
    @ApiOperation(value = "关联查询反馈详情(共用)", notes = "查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "reauserId", value = "中间表主键", dataType = "Long")
    })
    @GetMapping("/queryReactionDetails")
    public AjaxResult queryReactionDetails(TReactionInfo tReactionInfo){
        return tReactionInfoService.queryReactionDetails(tReactionInfo);
    }

    /**
     * 查询反馈信息列表
     * @Author wsf
     * @Date 9:08 2021/8/19
     * @param tReactionInfo
     **/
    @ApiOperation(value = "查询反馈信息列表(微信端)", notes = "查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "reactionType", value = "反馈类型(0自己事，1村里事)",dataType = "Integer"),
            @ApiImplicitParam(name = "reactionStateEmus", value = "反馈事件处理状态(0已提交，1处理中，2已解决)", dataType = "Long"),
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Long"),
            @ApiImplicitParam(name = "villageName", value = "村名姓名", dataType = "String"),
    })
    @GetMapping("/querySonReactionList")
    public AjaxResult querySonReactionList(TReactionInfo tReactionInfo)
    {
        startPage();
        List<TReactionInfo> reactionList = tReactionInfoService.querySonReactionList(tReactionInfo);
        return AjaxResult.success("success",reactionList);
    }

    /**
     *
     * 功能描述: 获取反馈信息详细信息
     * @author hxc
     * @param id
     */
    @ApiOperation(value = "查询反馈详情", notes = "查询")
    @PreAuthorize("@ss.hasPermi('interest:reaction:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfoById(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tReactionInfoService.selectTReactionInfoById(id));
    }

    /**
     * 查询反馈信息列表(钉钉端)
     * @Author yzj
     * @Date 9:08 2021/8/19
     * @param tReactionInfo
     **/
    @ApiOperation(value = "查询反馈信息列表(钉钉端)", notes = "查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "reactionType", value = "反馈类型(0自己事，1村里事)",dataType = "Integer"),
            @ApiImplicitParam(name = "reactionStateEmus", value = "反馈事件处理状态(0已提交，1处理中，2已解决)", dataType = "Long"),
            @ApiImplicitParam(name = "communityId", value = "社区id", dataType = "Long"),
            @ApiImplicitParam(name = "communityGroupId", value = "社区组别id", dataType = "Long"),
            @ApiImplicitParam(name = "villageName", value = "村名姓名", dataType = "String"),
    })
    @GetMapping("/queryHeadReactionList")
    public AjaxResult queryHeadReactionList(TReactionInfo tReactionInfo){
        startPage();
        List<TReactionInfo> reactionList = tReactionInfoService.queryHeadReactionList(tReactionInfo);
        return AjaxResult.success("success", reactionList);
    }

    /**
     * 功能描述: 查询已评论事件列表
     * @author yzj
     * @param tReactionInfo
     */
    @ApiOperation(value = "查询已评论事件列表(微信端)", notes = "查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Long"),
    })
    @GetMapping("/queryReactionListByDis")
    public AjaxResult queryReactionListByDis(TReactionInfo tReactionInfo){
        startPage();
        List<TReactionInfo> reactionList = tReactionInfoService.queryReactionListByDis(tReactionInfo);
        return AjaxResult.success("success", reactionList);
    }

}
